#ifndef _COMMAND_H
#define _COMMAND_H

#include <compiler.h>

struct cmd {
	const char *name;
	int (*fun)(int argc, char *argv[]);
	const char *help;
	const char *usage;
};

#define MBOOT_CMD(_name, _fun, _help, _usage)						\
	struct cmd __command_##name										\
		__always_unused __aligned(4) __section(.__commands) = {		\
		.name  = #_name,											\
		.fun   = _fun,												\
		.help  = _help,												\
		.usage = _usage }

int cmd_usage(const struct cmd *cmd);
struct cmd *cmd_search(const char *name);

extern struct cmd __commands_start[], __commands_end[];

#define for_each_command(p)                                              \
    for ((p) = __commands_start; (p) < __commands_end; (p)++)       

#endif /* _COMMAND_H */
